package com.qzsoft.zhjd.machine.modules.machinedaily.entity;

import java.math.BigDecimal;
import java.util.Date;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @ClassName MachineDailyWorkrecordsEntity
 * @Description 机械工时记录
 * @author linhuawei
 * @since 2021-10-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
@TableName("machine_daily_workrecords")
public class MachineDailyWorkrecordsEntity {

    /**
     * 主键
     */
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;

    /**
     * 机械主键
     */
    private String machineId;

    /**
     * 机械唯一编码
     */
    private String machineKey;

    /**
     * 日报主键
     */
    private String dailyId;

    /**
     * 开始时间
     */
    private Date startTime;

    /**
     * 结束时间
     */
    private Date endTime;
    
    /**
     * 开始范围
     */
    private BigDecimal startRang;
    
    /**
     * 结束范围
     */
    private BigDecimal endRang;
    
    /**
     * 时长
     */
    private Long duration;

    /**
     * 状态
     */
    private String state;

    /**
     * 日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd",  timezone = "GMT+8")
    private Date reportDate;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE, updateStrategy = FieldStrategy.NEVER)
    private Date createDate;

    /**
     * 范围长度
     */
    @TableField(exist = false)
    private BigDecimal rangLen;
    
    public BigDecimal getRangLen() {
        if(null != endRang && null != startRang) {
            return endRang.subtract(startRang);
        }
        return null;
    }

}
